<include file="public@admin_head" />
<style>
    .tab-content {
        padding: 1.5rem 3rem;
    }

    textarea {
        resize: none;
    }
</style>
</head>
<body>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class=""><a href="#plugins_name" data-toggle="tab">{:lang('PLUGINS_NAME')}</a></li>
            <li class=""><a href="#data_clear" data-toggle="tab">{:lang('DATA_CLEAR')}</a></li>
            <li class=""><a href="#comment_list" data-toggle="tab">{:lang('COMMENT_LIST')}</a></li>
            <li class=""><a href="#update_menu" data-toggle="tab">{:lang('UPDATE_MENU')}</a></li>
            <li class=""><a href="#admin_login_expire" data-toggle="tab">{:lang('ADMIN_LOGIN_EXPIRE')}</a></li>
            <li class=""><a href="#debugging_function" data-toggle="tab">{:lang('DEBUGGING_FUNCTION')}</a></li>
            <li class=""><a href="#log_list" data-toggle="tab">{:lang('LOG_LIST')}</a></li>
            <li class=""><a href="#bt_manage" data-toggle="tab">{:lang('BT_MANAGE')}</a></li>
        </ul>
        <fieldset>
            <div class="tabbable">
                <div class="tab-content">
                    <div class="tab-pane" id="plugins_name">
                        <div class="alert alert-info mt-3" role="alert">
                            专为ThinkCMF打造的管理工具<br />
                            当前版本：<br />
                            {$info.name} v{$info.version}<br />
                            ThinkCMF v{:cmf_version()}<br />
                            ThinkPHP v{:TpCommon::getVersion()}<br />
                            PHP v{:PHP_VERSION}<br />
                        </div>
                        <div class="form-group">
                            <pre>
                                    <code>
                                                                           ...     .............          
                                                                         ..   .:!o&*&&&&&ooooo&; .        
                                                                       ..  .!*%*o!;.                      
                                                                     ..  !*%*!.      ...                  
                                                                    .  ;$$!.   .....                      
                                                         ........... .*#&   ...                           
                                                                    :$$: ...                              
                                                         .;;;;;;;:::#%      ...                           
                                                       . *@ooooo&&&#@***&&;.   .                          
                                                       . *@       .@%.::;&%$*!. . .                       
                                         ................!@;......$@:      :@@$.                          
                                                         .@!   ..!@&.:::::::*@@*.:..............          
                                       . :!!!!!!!!!!ooooo&@$*%%%*#@&*&&&&&&&*@@$&&&oooooooooooo.          
                                       . :!!!!!!!!;;!;;:::@#;::.;@*         *@@o                          
                                                          @$    &@!.....  .*@@&................           
                                         ................:@* .  ##.     .o#@%;                            
                                                       . &@%..:;@$:;!o&*$#*;  ..                          
                                                       . ;@@#$$$@#**&o!;:   ..                            
                                                          :;:: !@;        ..                              
                                                              ;@*........                                 
                                                      ....   !@* ..                                       
                                                ......    .!%$! ..     | AUTHOR: dfer
                                        ......        .;o*%*!  .       | EMAIL: df_business@qq.com
                                               .:;;o&***o;.   .        | QQ: 3504725309
                                       .;;!o&****&&o;:.    ..          | WEBSITE: http://www.dfer.site    
                                    </code>
                                </pre>
                        </div>
                        <div class="form-group">
                            <if cmf_version() egt 8>
                                <!-- >=ThinkCMF8 -->
                                <a class="btn btn-xs btn-success js-ajax-dialog-btn" href="javascript:void(0);"
                                    data-method="put" data-href="admin/plugins/{$info.name}" data-msg="确定更新该插件吗？"
                                    title="{:lang('Update')}" data-toggle="tooltip">
                                    <i class="fa fa-refresh fa-fw"></i>
                                </a>

                                <if condition="$info['status']==0">
                                    <a class="btn btn-xs btn-success js-ajax-dialog-btn" href="javascript:void(0);"
                                        data-href="admin/plugins/{$info.id}/status/1" data-msg="确定启用该插件吗？"
                                        title="{:lang('Enable')}" data-toggle="tooltip">
                                        <i class="fa fa-toggle-on fa-fw"></i>
                                    </a>
                                    <else />
                                    <a class="btn btn-xs btn-warning js-ajax-dialog-btn" href="javascript:void(0);"
                                        data-href="admin/plugins/{$info.id}/status/0" data-msg="确定禁用该插件吗？"
                                        title="{:lang('Disable')}" data-toggle="tooltip">
                                        <i class="fa fa-toggle-off fa-fw"></i></a>
                                </if>
                                <a class="btn btn-xs btn-danger js-ajax-delete" href="javascript:void(0);"
                                    data-href="admin/plugins/{$info.id}" data-msg="确定卸载该插件吗？"
                                    title="{:lang('Uninstall')}" data-toggle="tooltip">
                                    <i class="fa fa-trash fa-fw"></i></a>

                                <else />
                                <!-- <ThinkCMF8 -->
                                <a class="btn btn-xs btn-success js-ajax-dialog-btn"
                                    href="{:url('admin/Plugin/update',array('name'=>$info['name']))}"
                                    data-msg="确定更新该插件吗？">{:lang('Update')}</a>

                                <if condition="$info['status']==0">
                                    <a class="btn btn-xs btn-success js-ajax-dialog-btn"
                                        href="{:url('admin/Plugin/toggle',array('id'=>$info['id'],'enable'=>1))}"
                                        data-msg="确定启用该插件吗？">{:lang('Enable')}</a>
                                    <else />
                                    <a class="btn btn-xs btn-warning js-ajax-dialog-btn"
                                        href="{:url('admin/Plugin/toggle',array('id'=>$info['id'],'disable'=>1))}"
                                        data-msg="确定禁用该插件吗？">{:lang('Disable')}</a>
                                </if>

                                <a class="btn btn-xs btn-danger js-ajax-dialog-btn"
                                    href="{:url('admin/Plugin/uninstall',array('id'=>$info['id']))}"
                                    data-msg="确定卸载该插件吗？">{:lang('Uninstall')}</a>
                            </if>
                        </div>
                    </div>

                    <div class="tab-pane" id="data_clear">
                        <form class="js-ajax-form" role="form"
                            action="{:cmf_plugin_url('DferThinkcmfTools://AdminIndex/clearThemeMorePost')}"
                            method="PUT">
                            <div class="form-group row">
                                <label for="input-site-name" class="col-sm-1 control-label"><span
                                        class="text-danger">*</span>{:lang('THEME_NAME')}</label>
                                <div class="col-md-3">
                                    <input type="text" class="form-control" id="input-site-name"
                                        name="options[theme_name]" value="{$config['theme_name']|default=''}"
                                        readonly />
                                    <p class="help-block">清除模板配置数据(more、config_more)，以及站点缓存</p>
                                </div>
                                <div class="col-sm-offset-2">
                                    <button type="submit" class="btn btn-primary js-ajax-submit" data-refresh="1">
                                        {:lang('CLEAR')}
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="tab-pane" id="comment_list">
                        <div class="form-group">
                            <label for="input-site-name" class="col-2 control-label">钩子调用</label>
                            <div class="col-10">
                                <code>
                                    &lt;hook name="guestbook" /&gt;
                                </code>
                                <p class="help-block">直接放到html中</p>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="input-site-name" class="col-2 control-label">提交接口</label>
                            <div class="col-10">
                                <code>
                                    cmf_plugin_url('DferThinkcmfTools://ApiUserMessageBoard/addMessage')
                                </code>
                                <p class="help-block">接口地址</p>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="input-site-name" class="col-2 control-label">菜单地址</label>
                            <div class="col-10">
                                <code>
                                    plugin/DferThinkcmfTools/AdminIndex/messageBoard
                                </code>
                            </div>
                            <div class="col-10">
                                <code>
                                    http://{domain name}/plugin/dfer_thinkcmf_tools/admin_index/messageboard.html
                                </code>
                            </div>
                        </div>
                    </div>

                    <div class="tab-pane" id="update_menu">
                        <div class="table-actions">
                            <a class="btn btn-warning"
                                href="{:cmf_plugin_url('DferThinkcmfTools://AdminMenu/getActionsAll')}">{:lang('ADMIN_MENU_GETACTIONS_ALL')}</a>
                        </div>
                    </div>

                    <div class="tab-pane" id="admin_login_expire">
                        <form class="js-ajax-form" role="form"
                            action="{:cmf_plugin_url('DferThinkcmfTools://AdminIndex/setSessionConfig')}" method="PUT">
                            <div class="form-group row">
                                <label class="col-sm-1 control-label">设置</label>
                                <div class="col-sm-8">
                                    <code>
                                        /data/config/session.php
                                    </code>
                                    <textarea class="form-control" name="session_content"
                                        rows="5">{$session_content}</textarea>
                                    <p class="help-block">
                                        直接覆盖`session.php`，保存之后立即生效（可通过F12查看Cookie里PHPSESSID字段的Expires属性）</p>
                                </div>
                                <div class="col-sm-offset-2">
                                    <button type="submit" class="btn btn-primary js-ajax-submit" data-refresh="1">
                                        保存
                                    </button>
                                </div>
                            </div>
                            <if !$v8>
                                <div class="form-group row">
                                    <label class="col-sm-1 control-label"></label>
                                    <div class="col-sm-8">
                                        <code>
                                            /data/config/cookie.php
                                        </code>
                                        <textarea class="form-control" name="cookie_content"
                                            rows="5">{$cookie_content}</textarea>
                                        <p class="help-block">
                                            直接覆盖`cookie.php`，tc5、6需要配合session使用</p>
                                    </div>
                                </div>
                            </if>


                            <div class="form-group row">
                                <label for="input-site-name" class="col-sm-1 control-label">参考</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" rows="5" readonly>{$session_content_demo}</textarea>
                                    <p class="help-block">`name`为session的id使用的参数名，`expire`为过期时间，以秒为单位（`60*60*24*5`为5天）
                                    </p>
                                </div>
                            </div>
                            <if !$v8>
                                <div class="form-group row">
                                    <label for="input-site-name" class="col-sm-1 control-label"></label>
                                    <div class="col-sm-10">
                                        <textarea class="form-control" rows="5"
                                            readonly>{$cookie_content_demo}</textarea>
                                        <p class="help-block">
                                            `expire`为过期时间，以秒为单位（`60*60*24*5`为5天）
                                        </p>
                                    </div>
                                </div>
                            </if>
                            <div class="form-group row">
                                <label for="input-site-name" class="col-sm-1 control-label">运行逻辑</label>
                                <div class="col-sm-10">
                                    <code>
                                        默认以文件方式保存，参考`/vendor/topthink/framework/src/think/session/driver/File.php`，
                                        存储在`data/runtime/session/sess_{ID}`，
                                        浏览器cookie会存储`PHPSESSID`（对应`session.php`的`name`）,值为:{ID}，过期时间对应`session.php`的`expire`，
                                        {ID}为一段随机字符串，失效之后会生成新的
                                    </code>
                                    <p class="help-block"></p>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="tab-pane" id="debugging_function">
                        <form class="js-ajax-form" role="form"
                            action="{:cmf_plugin_url('DferThinkcmfTools://AdminIndex/setEnvConfig')}" method="PUT">
                            <div class="form-group row">
                                <label class="col-sm-1 control-label">设置</label>
                                <div class="col-sm-8">
                                    <code>
                                        .env
                                    </code>
                                    <textarea class="form-control" name="env_content" rows="5">{$env_content}</textarea>
                                    <p class="help-block">
                                        直接覆盖项目根路径下的`.env`，保存之后立即生效</p>
                                </div>
                                <div class="col-sm-offset-2">
                                    <button type="submit" class="btn btn-primary js-ajax-submit" data-refresh="1">
                                        保存
                                    </button>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="input-site-name" class="col-sm-1 control-label">参考</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" rows="5" readonly>{$env_content_demo}</textarea>
                                    <p class="help-block">
                                        APP_DEBUG：1 开启调试 0 关闭调试
                                    </p>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="tab-pane" id="log_list">
                        <div>
                            <p class="help-block" style="position: fixed;bottom: 35%;right: 3%;">
                                <a class="btn btn-primary"
                                    href="{:cmf_plugin_url('DferThinkcmfTools://AdminIndex/index',['tab'=>'log_list'])}">刷新</a>
                            </p>
                            <pre>
                            <code>
                                {$log_content}
                            </code>
                            </pre>
                        </div>
                    </div>

                    <div class="tab-pane" id="bt_manage">
                        <div class="alert alert-info mt-3" role="alert">
                            当前服务器：{$panel_host}。调用宝塔接口管理网站，需要设置bt秘钥。<br />
                            <if !isset($site_list['data'])>
                                错误信息：{$site_list.msg??$site_list}
                            </if>

                        </div>
                        <div>
                            <if isset($site_list['data'])>
                                <table class="table table-hover table-bordered table-list">
                                    <thead>
                                        <tr>
                                            <th>{:lang('KEY')}</th>
                                            <th>{:lang('NAME')}</th>
                                            <th>{:lang('PATH')}</th>
                                            <th>{:lang('VERSION')}</th>
                                            <th>{:lang('STATUS')}</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <foreach name="site_list.data" item="vo">
                                            <tr>
                                                <td>{$vo.id}</td>
                                                <td><a target="_blank" href="http://{$vo.name}">{$vo.name}</a></td>
                                                <td>{$vo.path}</td>
                                                <td>{$vo.php_version}</td>
                                                <td>
                                                    <if condition="$vo.status == 1">
                                                        <span class="label label-success">{$status[$vo.status]}</span>
                                                        <else />
                                                        <span class="label label-danger">{$status[$vo.status]}</span>
                                                    </if>
                                                    <a class="btn btn-xs btn-primary" data-title="{$vo.name}"
                                                        data-url="{:cmf_plugin_url('DferThinkcmfTools://AdminIndex/siteSetup',['site_id'=>$vo['id']])}"
                                                        href="javascript:;"
                                                        onclick="openDesignDialog(this)">{:lang('Setup')}</a>
                                                </td>
                                            </tr>
                                        </foreach>
                                    </tbody>
                                </table>
                            </if>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>

    </div>
    <script type="text/javascript" src="__STATIC__/js/admin.js?v={$_static_version}"></script>
    <script>
        $(() => {
            console.log('{$tab}');
            $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
                console.log(e);
                var href = $(e.target).attr('href');
                switch (href) {
                    case '#log_list':
                        window.scrollTo(0, document.body.scrollHeight);
                        break;
                    default:
                        break;
                }
            })
            $('a[href=#{$tab}]').tab('show');
        })

        function openDesignDialog(obj) {
            var $obj = $(obj);
            var url = $obj.data('url');
            var title = $obj.data('title');
            parent.openIframeLayer(url, title, {
                area: GV.IS_MOBILE ? ['100%', '100%'] : ['700px', '90%'],
                offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto'
            });
        }
    </script>
</body>
</html>